package restful

import (
	"net/http"
	"vblog/apps/blog"

	"github.com/infraboard/mcube/client/rest"
)

//v1 版本
// func NewClient(token string) *Client {
// 	c := http.DefaultClient
// 	return &Client{
// 		Address: "http://0.0.0.0:8800",
// 		Token:   token,
// 		client:  c,
// 	}
// }

// // 配置address 核心http client
// type Client struct {
// 	Address string
// 	Token   string
// 	client  *http.Client
// }

// func (c *Client) BlogClient() blog.Service {
// 	return &BlogClient{
// 		conn: c,
// 	}
// }

// v2版本

func NewClient(token string) *Client {
	// 获取一个RestfulClient对象
	c := rest.NewRESTClient()
	c.SetBaseURL("http://0.0.0.0:8800")
	c.SetCookie(&http.Cookie{
		Name:  "token",
		Value: token,
	})
	return &Client{
		c: c,
	}
}

type Client struct {
	c *rest.RESTClient
}

func (c *Client) BlogClient() blog.Service {
	return &BlogClient{
		conn: c.c,
	}
}
